using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using MM.Entities;

namespace MM.Business
{
    class clsIMPA_REF_TABLE
    {
        public clsIMPA_REF_TABLE(string sConn)
        {
            SqlHelper.ConnectionString = sConn;
        }
        public List<IMPA_REF_TABLE> DataTableToLstObj(DataTable dt)
        {
            IMPA_REF_TABLE refTableDTO;
            List<IMPA_REF_TABLE> lstRefTableDTO = new List<IMPA_REF_TABLE>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                refTableDTO = new IMPA_REF_TABLE();
                try
                {
                    refTableDTO._l1Code = int.Parse(dt.Rows[i]["L1Code"].ToString());
                }
                catch (Exception ex)
                {
                }
                try
                {
                    refTableDTO._l1Name = dt.Rows[i]["L1Name"].ToString();
                }
                catch (Exception ex)
                {
                }
                lstRefTableDTO.Add(refTableDTO);
            }
            return lstRefTableDTO;
        }
        public IMPA_REF_TABLE DataTableToObj(DataTable dt)
        {
            IMPA_REF_TABLE refTableDTO;
            refTableDTO = new IMPA_REF_TABLE();
            try
            {
                refTableDTO._l1Code = int.Parse(dt.Rows[0]["L1Code"].ToString());
            }
            catch (Exception ex)
            {
            }
            try
            {
                refTableDTO._l1Name = dt.Rows[0]["L1Name"].ToString();
            }
            catch (Exception ex)
            {
            }
            return refTableDTO;
        }
        public List<IMPA_REF_TABLE> LoadImpaRefTable()
        {
            DataTable dt = new DataTable();
            List<IMPA_REF_TABLE> lstRefTableDTO = new List<IMPA_REF_TABLE>();
            try
            {
                SqlHelper.OpenConnection();
                string spName = "usp_SelectIMPA_REF_TABLEsAll";
                dt = SqlHelper.ExecuteToDataTable(spName, CommandType.StoredProcedure);
                lstRefTableDTO = DataTableToLstObj(dt);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (!SqlHelper.IsHaveTran())
                    SqlHelper.CloseConnection();
            }
            return lstRefTableDTO;
        }
    }
}